function [ t,means_mean ] =     generateFestPlot(type, variance,repeat, startp, endp,seqname )
addpath('../core_f','../core_ransac','../core_gen_gt','../core_gen_synth','../core_gen_real','../core_matching');
% start outlier ratio from zero and go to 80% outlier ratio
if (nargin <5)
    startp=0;
    endp=0.8;
end

% repeat each outlier ratio 100 times
if (nargin <3)
   repeat=100;
end

% fixing the number of matches per image per to be 400, synthetic only
numN=400;

% gaussian error added to all matches
gaussianerrorstd=0;

% number of steps for the x axis fixed to be 8
numPoints=8;


tStartprogram=tic;



topfoldername='../newfestdatafiles';
curdirname= chooserightfolder(clock(),topfoldername);

mkdir([curdirname '/extras']);
mkdir([curdirname '/code']);
logs1 = fopen([curdirname '/arguments.txt'  ], 'wt');
fprintf(logs1,' type: %s \n variance: %s \n  repeatEach %f \n  startp %f \n  endp %f \n seqname: %s \n',type, variance,repeat, startp, endp,seqname );
fclose(logs1);



AlgNames={'RANSAC','MSAC','MLESAC','cookUpdate','Liang','Residuals'};


numalgs=size(AlgFuncs,2);


SampEr=zeros(numPoints,numalgs, repeat);
iterations=zeros(numPoints,numalgs, repeat);
cpuTime=zeros(numPoints,numalgs, repeat);

% x axis
t=startp:((endp-startp)/(numPoints-1)):endp;


numTotalIterations=numPoints*repeat;
currIteration=0;




for i=1:numPoints
       
    for j=1:repeat
       
        currIteration=currIteration+1;
        display(['iteration ' currIteration ' out of ' numTotalIterations ' outlier ratio: ' num2str(t(i))]);  
        
         if(strcmp(type,'synthetic')==1)
[ ~, ~,~ , badpoints,corrs, ~, ~,~,~,width,height,~,cleancorrs ] = generateF( 0, 0,1,0,1,2,t(i),1,1024,768,gaussianerrorstd,0 );          
        elseif(strcmp(type,'oxford')==1)
        [corrs, ~, ~,~, ~ , ~, ~, ~,~,~,inlierOutlier,cleancorrs,width,height,~] = readCorrsOxford( seqname ,t(i), 1,2,gaussianerrorstd);   
             elseif(strcmp(type,'sift')==1)
        % how do you evaluate F in this case since no ground truth is
        % known? look into lit, perhaps variance of inliers? Torr had some
        % in his paper
            [ MF,corrs,ks,height,width, FFORMATTED,IMS,corrsFormatted,corrsall,corrsFormattedall] = generateFImages( seqname,t(i), 1,0 );
         display('not imeplemented yet');
         else
             error('incorrect parameter TYPE used');
         end
        
        
        
        for k=1:numalgs
            
            tic;
           
            
            [F, current_errors_iterations{i}(k,j),pvizout]= fundmatrixrobustgeneral(corrs,AlgFuncs{k});
            PtElapsed=toc;
            totalAgltime=totalAgltime+PtElapsed;
            
            [bestInliers, bestF, d, current_errors_samp_mean{i}(k,j),current_errors_samp_var{i}(k,j),current_errors_samp_median{i}(k,j),current_errors_inlier{i}(k,j)] = sampsonF(F, corrsclean, tt);
            % left off herer ZZZZZZZZZZZZZZZZZZZZ
            fprintf(comletesolsf, [  num2str(current_errors_samp_mean{i}(k,j)) ' , ' num2str(current_errors_samp_var{i}(k,j)) ' , ' num2str(current_errors_samp_median{i}(k,j)) ' , '  num2str(current_errors_inlier{i}(k,j))  ' , ']);
            
            disp(['algorithm: ' AlgNames{k} ' had mean error ' num2str(current_errors_samp_mean{i}(k,j)) ' and error variance: ' num2str(current_errors_samp_var{i}(k,j))  ' inliers: '  num2str(current_errors_inlier{i}(k,j)) ' time: ' num2str(PtElapsed)]);
            fprintf(dispfid,['\nalgorithm: ' AlgNames{k} ' had mean error ' num2str(current_errors_samp_mean{i}(k,j)) ' and error variance: ' num2str(current_errors_samp_var{i}(k,j)) ' and error median: ' num2str(current_errors_samp_median{i}(k,j)) ' iterations: '  num2str(current_errors_iterations{i}(k,j)) ' inliers: '  num2str(current_errors_inlier{i}(k,j)) ' time: ' num2str(PtElapsed)]);
            
            
            
            fprintf(fid, 'algorithm %s mean error %6.2f median error %6.2f variance error %6.2f number inliers %d number iterations %d and time elapsed is %6.2f \n',AlgNames{k},current_errors_samp_mean{i}(k,j),current_errors_samp_mean{i}(k,j),current_errors_samp_mean{i}(k,j),current_errors_inlier{i}(k,j) ,current_errors_iterations{i}(k,j) ,PtElapsed  );
            
        end
        
        tElapsed=toc(tStart);
        disp(['iteration ' num2str(currIteration) ' took ' num2str(tElapsed) ' seconds' ' and total time spent in algs is ' num2str(totalAgltime) ' time remaining: ' ' out of ' num2str(tElapsed*(numTotalIterations-currIteration))]);
        fprintf(dispfid,['\niteration ' num2str(currIteration) ' took ' num2str(tElapsed) ' seconds' ' and total time spent in algs is ' num2str(totalAgltime) ' time remaining: ' ' out of ' num2str(tElapsed*(numTotalIterations-currIteration))]);
    end
    
    disp('______________________________________________________');
    fprintf(dispfid,['\n______________________________________________________']);
    
    fprintf(fidgraph, '%6.2f , ' ,t(1,i));
    %now calculate the stat for the current run
    for k=1:numalgs
        means_mean(k,i)=mean(current_errors_samp_mean{i}(k,:));
        medians_mean(k,i)=median(current_errors_samp_mean{i}(k,:));
        variances_mean(k,i)=var(current_errors_samp_mean{i}(k,:));
        
        means_med(k,i)=mean(current_errors_samp_median{i}(k,:));
        medians_med(k,i)=median(current_errors_samp_median{i}(k,:));
        variances_med(k,i)=var(current_errors_samp_median{i}(k,:));
        
        means_var(k,i)=mean(current_errors_samp_var{i}(k,:));
        means_inliers(k,i)=mean(current_errors_inlier{i}(k,:));
        means_iterations(k,i)=mean(current_errors_iterations{i}(k,:));
        
        fprintf(fidgraph, ' %6.2f , %6.2f  , %6.2f ,  %6.2f , %6.2f  ,  %6.2f , %6.2f  ,  %6.2f  ,   %6.2f  ,' ,means_mean(k,i),medians_mean(k,i),  variances_mean(k,i),means_med(k,i),medians_med(k,i),variances_med(k,i), means_var(k,i),means_iterations(k,i),means_inliers(k,i));
    end
    
    fprintf(fidgraph, ' \n');
    fclose(comletesolsf);
    
end

% for focal length
data={means_mean,  medians_mean,variances_mean,means_inliers,means_iterations };
dataNames={'means of errors', 'medians of errors', 'variance of errors','inliers','iterations'};
sizeDataCats=size(data,2);

for i=1:sizeDataCats
    % the mean stuff
    figure;
    hold;
    for k=1:numalgs
        
        plot(t,data{i}(k,:),styles{k});
    end
    xlabel(['x outlier ratio']);       %  add axis labels and plot title
    ylabel(['y ' dataNames{i}]);
    title([ ' plot of ' dataNames{i} label ' versus error ratio']);
    legend(AlgNames);
    saveas(gcf,[curdirname '/param'   dataNames{i} nowtime '.fig']);
    saveas(gcf,[curdirname '/param_center_'   dataNames{i} nowtime '.jpg']);
    saveas(gcf,[curdirname '/param_center_' dataNames{i} nowtime '.eps'],'epsc');
    
    
    hold
    
end




for k=1:numalgs
    clear   cvsMatrix
    clear iterMatrix
    for j=1:repeat
        
        for i=1:numPoints
            cvsMatrix(j+1,i+1)=current_errors_samp_mean{i}(k,j);
            cvsMatrix(1,i+1)=n(1,i);
            cvsMatrix(j+1,1)=j;
            
            iterMatrix(j+1,i+1)=current_errors_iterations{i}(k,j);
            iterMatrix(1,i+1)=n(1,i);
            iterMatrix(j+1,1)=j;
        end
    end
    dlmwrite([curdirname '/datasamplers_'  AlgNames{1,k}  '.csv'], cvsMatrix);
    dlmwrite([curdirname '/datasamplers_iters_'  AlgNames{1,k}  '.csv'],iterMatrix);
end



fclose(fid);
fclose(fidgraph);
fclose(dispfid);
save( [curdirname '/variables_GP' nowtime '.mat']);

tElapsedprogram=toc(tStartprogram);
disp([' program took ' num2str(tElapsedprogram) ' seconds']);
copyfile('*.m',[curdirname '\matlabfiles']);
copyfile('robustfiles',[curdirname '\matlabfiles\robustfiles']);
copyfile('fundMatrix',[curdirname '\matlabfiles\fundMatrix']);
%copyfile(curdirname,['H:\matlabs\' curdirname ]);
end

function fname=chooserightfolder(mtime,topfolder)
mtime=clock;
subdirname=['subdir_m_' num2str(mtime(1,2)) '_d_' num2str(mtime(1,3)) '_h_' num2str(mtime(1,4)) '_s_' num2str(ceil(mtime(1,5))) '_v'];
direxists=1;

while(direxists==1)
    
    dircount=dircount+1;
    
    curdirname=[topfolder '/' subdirname num2str(dircount)];
    
    if(exist(curdirname,'dir')==0)
        mkdir(curdirname);
        direxists=0;
    end
    
end
fname= curdirname;
end